package com.alinesno.cloud.busines.shop.manage.rest;

import javax.servlet.http.HttpServletRequest;

import com.alinesno.cloud.common.facade.response.AjaxResult;
import io.lettuce.core.protocol.CommandHandler;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.alinesno.cloud.common.core.constants.SpringInstanceScope;
import com.alinesno.cloud.common.facade.pageable.DatatablesPageBean;
import com.alinesno.cloud.rest.gateway.adapter.plugins.TranslateCode;
import com.alinesno.cloud.rest.gateway.adapter.page.TableDataInfo;
import com.alinesno.cloud.rest.gateway.adapter.rest.BaseRestAdapter;

import com.alinesno.cloud.busines.shop.manage.entity.ItemEntity;
import com.alinesno.cloud.busines.shop.manage.service.IItemService;

import java.util.List;

/**
 * 商品Rest
 *
 * @author wangyongkang ${authorEmail}
 * @date 2022-03-17 23:48:40
 */
@RestController
@Scope(SpringInstanceScope.PROTOTYPE)
@RequestMapping("/api/shop-manage/Item")
public class ItemRest extends BaseRestAdapter<ItemEntity, IItemService> {

    //日志记录
    private static final Logger log = LoggerFactory.getLogger(ItemRest.class);

    @Autowired
    private IItemService itemService;

    @TranslateCode
    @ResponseBody
    @PostMapping("/datatables")
    public TableDataInfo datatables(HttpServletRequest request, Model model, DatatablesPageBean page) {
        log.debug("page = {}", ToStringBuilder.reflectionToString(page));
        return this.toPage(model, this.getFeign() , page) ;
    }

    @Override
    public IItemService getFeign() {
        return this.itemService;
    }

    @ResponseBody
    @GetMapping("/getData")
    public TableDataInfo getData(){
        List<ItemEntity> list =itemService.getList();
        list.size();
        TableDataInfo info = new TableDataInfo();
        info.setRows(list);
        info.setTotal(list.size());
        info.setCode(200);
        info.setMsg("获取成功");
        return info;
    }


}
